package com.wyw.leetcode.learning.medium;

import com.wyw.leetcode.simple.parent.ListNode;

import java.util.LinkedList;

/**
 * 文件介绍
 *
 * @Author Mr Wu yewen.wu.china@gmail.com
 * @Date 2023/2/16 15:52
 */
public class Topic002 {

    static LinkedList<Integer> stack1;
    static LinkedList<Integer> stack2;

    public static void main(String[] args) {

    }

    public static ListNode addTwoNumbers(ListNode l1, ListNode l2) {

        ListNode result = new ListNode();
        boolean carryFlag = false;

        while (l1 != null) {
            stack1.push(l1.val);
        }
        while (l2 != null) {
            stack2.push(l2.val);
        }

        while (stack1.isEmpty() || stack2.isEmpty()) {
            int tempResult;
            if(carryFlag) {
                tempResult = stack1.pop() + stack2.pop() + 1;
            } else {
                tempResult = stack1.pop() + stack2.pop();
            }

            if(tempResult > 10) {
                carryFlag = true;
                result.val = tempResult - 10;
                result.next = result;

            } else {
                carryFlag = false;
                result.val = tempResult;
                result.next = result;
            }
        }

//        if(stack1.isEmpty()) {
//            while () {
//
//            }
//        }
        return result;

    }
}
